package com.bytz.modules.cms.reseller.controller;

import com.bytz.common.api.vo.Result;
import com.bytz.modules.cms.reseller.entity.CouponReseller;
import com.bytz.modules.cms.reseller.service.ICouponResellerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Api(tags = "优惠券")
@RequestMapping("/coupon")
public class CouponController {

    @Autowired
    private ICouponResellerService couponResellerService;

    @ApiOperation("获取经销商所有可用优惠券")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public Result<List<CouponReseller>> list() {
        return Result.ok(couponResellerService.getByLoginReseller());
    }

    @ApiOperation("根据券码查找可用优惠券")
    @RequestMapping(value = "/search", method = RequestMethod.GET)
    public Result<List<CouponReseller>> search(@RequestParam String code) {
        return Result.ok(couponResellerService.searchByCode(code));
    }

    @ApiOperation("根据id查找可用优惠券")
    @RequestMapping(value = "/getById", method = RequestMethod.GET)
    public Result<CouponReseller> getById(@RequestParam String id) {
        return Result.ok(couponResellerService.getByIdAndLoginReseller(id));
    }

}

